#!/bin/bash
x=0
while :
do
    read -p "请输入用户名" user 
    #如果user是空值则重新进行循环任务
    [ -z "$user" ] && continue
    #如果user是0则退出循环执行循环后任务
    [ "$user" == 0 ] && break 
    useradd $user
    if [ $? -eq 0 ];then
        let x++
    else
        echo "无效用户名"
    fi

    stty -echo
    read -p "请输入密码" pass
    #如果用户没有输入密码，则默认密码为123
    pass=${pass:-123}  
    stty echo
    echo "$pass" | passwd --stdin $user   
done
echo "本次共创建$x个用户"    